<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>营养水果秒杀系统</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../public/css/font.css">
        <link rel="stylesheet" href="../public/css/xadmin.css">
        <script src="../public/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../public/js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <blockquote class="layui-elem-quote">
                                <form class="layui-form">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"><span class="x-red">*</span>水果</label>
                                        <div class="layui-input-inline">
                                            <!-- <select name="contrller">
                                                <option></option>
                                            </select> -->
                                        <!-- layui用select在火狐这里不兼容 -->
                                        {{range $fm := .fl}}<input name="specname" type="radio" value="{{$fm}}" title="{{$fm}}">
                                        {{end}}
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label for="L_repass" class="layui-form-label">
                                        </label>
                                        <button class="layui-btn" lay-filter="add" lay-submit="">
                                            提交
                                        </button>
                                    </div>
                                </form>
                            </blockquote>
                        </div>
                    </div>
                </div>
                <style id="welcome_style"></style>
                <div class="layui-col-md12">
                    <blockquote class="layui-elem-quote layui-quote-nm">感谢layui,百度Echarts,jquery,本系统由x-admin提供技术支持。</blockquote></div>
            </div>
        </div>
        </div>
        <script src="https://cdn.bootcdn.net/ajax/libs/jsencrypt/3.0.0-rc.1/jsencrypt.js"></script>
        <script>
        var PUBLIC_KEY = '{{.pubkey}}';
        var encrypt = new JSEncrypt();
        encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----'+PUBLIC_KEY+'-----END PUBLIC KEY-----');
        layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //监听提交
                form.on('submit(add)',
                function(data) {
                    console.log(data);
                    //发异步，把数据提交给php
                    if(data.field.specname == undefined || data.field.specname == "") {
                        layer.alert("请选中一个水果", {icon:2});
                        return false;
                    }
                    $.ajax({
                        url: "./spike",
                        type: "post",
                        data: {data: encrypt.encrypt(JSON.stringify({
                            id:{{.id}},
                            specname: data.field.specname,
                        }))},
                        dataType: "json",
                        success: function (resp) {
                            console.log(resp);
                            if (resp.status) {
                                layer.alert("提交成功", {icon:6},
                                    function() {
                                        //关闭当前frame
                                        // xadmin.close();
                                        // 可以对父窗口进行刷新 
                                        xadmin.father_reload();
                                    }
                                );
                            } else {
                                layer.alert("提交失败", {icon:2});
                            }
                        }
                    });
                    return false;
                });
            }
        );
        </script>
    </body>
</html>